<?php

/**
 * Accesses the tgp_account_feeds table in the thegridpaper database
 * This table is the ManyToMany connection table between tgp_accounts and tgp_feeds
 * @author panosbaroudjian
 *
 */
class Application_Model_DbTable_AccountFeeds extends Zend_Db_Table_Abstract
{
    protected $_name = 'tgp_account_feeds';
    protected $_primary = array('account_id', 'feed_id');
    protected $_referenceMap = array(
                                    'Account' => array('columns' => array('account_id'),
                                                    'refTableClass' => 'Application_Model_DbTable_Accounts',
                                                    'refColumns' => array('account_id'),
                                                    'onDelete' => self::CASCADE),
                                    'Feed' => array('columns' => array('feed_id'),
                                                    'refTableClass' => 'Application_Model_DbTable_Feeds',
                                                    'refColumns' => array('feed_id'),
                                                    'onDelete' => self::CASCADE));

    
    /**
     * Gets a row by its primary keys
     * @param int $account_id: The id of the account
     * @param int $feed_id: The id of the feed
     * @return NULL|multitype: An array containing the row
     */
    public function getById($account_id, $feed_id)
    {
        $account_id = (int)$account_id;
        $feed_id = (int)$feed_id;
        $row = $this->find($account_id, $feed_id);
        if (!$row)
        {
            return null;
        }
        return $row->toArray();
    }

    /**
     * Inserts a new row
     * @param int $account_id: The id of the account
     * @param int $feed_id: The id of the feed
     */
    public function insertAccountFeed($account_id, $feed_id)
    {
        $data = array('account_id' => (int)$account_id, 'feed_id' => (int)$feed_id);
        $this->insert($data);
    }

    /**
     * Deletes a row
     * @param int $account_id: The id of the account
     * @param int $feed_id: The id of the feed
     */
    public function deleteAccountFeed($account_id, $feed_id)
    {
        $where = array();
        $where['account_id = ?'] = (int)$account_id;
        $where['feed_id = ?'] = (int)$feed_id;
        $this->delete($where);
    }
}

